package live.jialing.sip.base.repository;

import live.jialing.core.data.jpa.CustomJpaRepository;
import live.jialing.sip.base.domain.Teacher;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 教职工
 */
public interface TeacherRepository extends CustomJpaRepository<Teacher, Long> {

    /**
     * 获取班级中该员工的老师信息
     *
     * @param classId    班级ID
     * @param employeeId 员工ID
     * @return
     */
    @Query("select t from Teacher t where t.squad.id = ?1 and t.employee.id = ?2")
    List<Teacher> findByClassIdAndTeacherId(long classId, long employeeId);

    /**
     * 获取班级中该科目的关系
     *
     * @param classId 班级ID
     * @param subject 科目
     * @return
     */
    @Query("select t from Teacher t where t.squad.id = ?1 and t.subject = ?2")
    Teacher findByClassIdAndSubject(long classId, String subject);

    /**
     * 获取班级中该职务的关系
     *
     * @param classId 班级ID
     * @param title   职务
     * @return
     */
    @Query("select t from Teacher t where t.squad.id = ?1 and t.title =?2")
    List<Teacher> findByClassIdAndTitle(long classId, String title);

    /**
     * 获取班级中该员工的老师信息
     *
     * @param classId    班级ID
     * @param employeeId 员工ID
     * @param title      职务
     * @return
     */
    @Query("select t from Teacher t where t.squad.id = ?1 and t.employee.id = ?2 and t.title =?3")
    List<Teacher> findByClassIdAndTeacherIdAndTitle(long classId, long employeeId, String title);

    /**
     * 获取班级中所有的老师：班主任、任课老师
     *
     * @param classId  班级ID
     * @return
     */
    @Query("select t from Teacher t where t.squad.id = ?1 ")
    List<Teacher> findAllByClass(long classId);
}